package com.mapler.service;

import com.mapler.model.AdModel;
import com.mapler.model.SModel;
import com.mapler.model.UAModel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.log4j.Logger;

/**
 *
 * @author none
 */
public class W4MWorker implements ITask{
    public ScheduledExecutorService executor =  Executors.newScheduledThreadPool(10);
    private SModel sModel;
    private ArrayList<UAModel> uaModels;
    ArrayList<AdModel> addModels;
    private HashMap<String,UAModel> usHashMap;
    private static Logger log = Logger.getLogger(W4MWorker.class);
    private INotifier iNotifier;
    private HashMap<Integer,ArrayList<AdModel>> addMap = new HashMap();
    private int globalWhichSlot;
    public W4MWorker(INotifier iNotifier,SModel sModel,ArrayList<UAModel> uaModels,ArrayList<AdModel> 
            addModels,HashMap<String,UAModel> usHashMap){
        this.sModel = sModel;
        this.uaModels = uaModels;
        this.addModels = addModels;
        this.usHashMap = usHashMap;
        this.iNotifier = iNotifier;
    }
    @Override
    public void update() {
        try {
            iNotifier.notify("W4M:: Going to start working.");
            W4MClick w4MClick = new W4MClick(iNotifier,this.sModel,this.uaModels,this.addModels,usHashMap);
            w4MClick.setAddMap(this.getAddMap());
            w4MClick.setGlobalWhichSlot(this.getGlobalWhichSlot());
            executor.submit(w4MClick);
        } catch (Throwable ex) {
            ex.printStackTrace();
            log.debug("update:: Error causes "+ex);
        }
    }

    @Override
    public void finish() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public HashMap<Integer, ArrayList<AdModel>> getAddMap() {
        return addMap;
    }

    public void setAddMap(HashMap<Integer, ArrayList<AdModel>> addMap) {
        this.addMap = addMap;
    }

    public int getGlobalWhichSlot() {
        return globalWhichSlot;
    }

    public void setGlobalWhichSlot(int globalWhichSlot) {
        this.globalWhichSlot = globalWhichSlot;
    }
}
